package work;

import java.util.Scanner;

/*
6 编程
   求一个int型的正整数,转成2进制以后, 里面有多少个1
 */
public class Work06 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入正整数：");
        int num = scanner.nextInt();

        int counts = countOne(num);
        System.out.println("转成2进制以后, 里面有"+counts+"个1");
    }
    static int countOne(int num){
        int counts = 0;
        while (num!= 0) {
            if (num % 2 == 1) {
                counts++;
            }
            num /= 2;
        }
        return counts;
    }
}
